<template>
	<view>
		<view class="top-view">
			<uni-nav-bar :statusBar="true" :border="false" backgroundColor="transparent">
			</uni-nav-bar>
			<view class="user-row" @click="navToInfo" v-if="token">
				<image :src="userInfo.headimage" class="avatar"></image>
				<view class="name-view">
					<view class="name">{{ userInfo.nickName || '' }}</view>
					<view class="phone">{{ userInfo.phone | maskPhone }}</view>
				</view>
				<view class="right-btn">
					<uni-icons type="right" color="#BBC3D5"></uni-icons>
				</view>
			</view>
			<view class="user-row" @click="toLogin" v-else>
				<image :src="userInfo.headPortrait" class="avatar"></image>
				<view class="name-view">
					<view class="name">登录</view>
					<view class="phone">暂未设置</view>
				</view>
				<view class="right-btn">
					<uni-icons type="right" color="#BBC3D5"></uni-icons>
				</view>
			</view>
		</view>
		<!-- <view class="mine-order-card"/> -->
		<view class="mine-order-card">
			<view class="title-view">
				<view class="title">我的订单</view>
				<view class="right-view" @click="navToMyOrderList('全部')">
					<view>全部</view>
					<uni-icons type="right" color="#BBC3D5"></uni-icons>
				</view>
			</view>
			<view class="grid-view">
				<uni-grid :column="4" :showBorder="false" :highlight="false" :square="false">
					<uni-grid-item>
						<view class="grid-item" @click="navToMyOrderList('待支付')">
							<image src="../../static/mine_icon_pay.png" class="icon"></image>
							<view class="text">待支付</view>
							<view class="grid-dot">
								<uni-badge :text="countInfo.paidNum" />
							</view>
						</view>
					</uni-grid-item>
					<uni-grid-item>
						<view class="grid-item" @click="navToMyOrderList('待审核')">
							<image src="../../static/mine_icon_review.png" class="icon"></image>
							<view class="text">待审核</view>
							<view class="grid-dot">
								<uni-badge :text="countInfo.checkNum" />
							</view>
						</view>
					</uni-grid-item>
					<uni-grid-item>
						<view class="grid-item" @click="navToMyOrderList('待出发')">
							<image src="../../static/mine_icon_go.png" class="icon"></image>
							<view class="text">待出发</view>
							<view class="grid-dot">
								<uni-badge :text="countInfo.setOutNum" />
							</view>
						</view>
					</uni-grid-item>
					<uni-grid-item>
						<view class="grid-item" @click="navToMyOrderList('待服务')">
							<image src="../../static/mine_icon_serve.png" class="icon"></image>
							<view class="text">待服务</view>
							<view class="grid-dot">
								<uni-badge :text="countInfo.serviceNum" />
							</view>
						</view>
					</uni-grid-item>
				</uni-grid>
			</view>

		</view>

		<view class="menu-list">
			<uni-list :border="false">
				<uni-list-item to="/patientAppPages/pages/patientsList/patientsList"
					:thumb="require('../../static/mine_item_patient.png')" title="就诊人信息" showArrow></uni-list-item>
				<uni-list-item :thumb="require('../../static/mine_icon_feedback.png')" title="投诉反馈"
					showArrow></uni-list-item>
				<uni-list-item :thumb="require('../../static/mine_icon_feedback.png')" title="操作指南"
					showArrow></uni-list-item>
			</uni-list>
		</view>

		<!-- 		<view class="exit-btn">
			退出账号
		</view> -->


	</view>
</template>

<script>
import * as userInfo from '../../common/api/userInfo.js'
import * as orderInfo from '../../common/api/orderInfo.js'
import * as loginUtils from '../../utils/loginUtils.js'
import { getUserMessage } from "@/api/feixiang/application.js"
import { getToken } from "@/utils/auth.js"
export default {
	data() {
		return {
			userInfo: {},
			orderNum: {
				'待支付': '',
				'待审核': '',
				'待出发': '',
				'待服务': '',
			},
			countInfo: {},
			token: getToken(),
		}
	},
	onShow() {

	},
	filters: {
		maskPhone(phone) {
			return phone ? phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : ""
		}
	},
	mounted() {
		this.login()
		this.getUserInfo()
		// this.getOrderNums()
		this.queryCountByComm()
	},
	methods: {
		toLogin() {
			uni.navigateTo({
				url: "/sickbed/pages/feixiang/login/login"
			})
		},
		login() {
			loginUtils.checkRegister()
			// loginUtils.login()
		},
		getUserInfo() {
			const openid = uni.getStorageSync('openid_key')
			const param = {
				openId: openid
			}
			getUserMessage(param).then(result => {
				this.userInfo = result.data
			}).catch(error => {
				console.log(error);
			})
		},
		getOrderNums() {
			this.getOrderNum(['待支付'], '待支付')
			this.getOrderNum(['待评估'], '待评估')
			this.getOrderNum(['待出发'], '待出发')
			this.getOrderNum(['待服务'], '待服务')
		},
		getOrderNum(statusList = [], key = '') {
			const param = {
				pageIndex: 1,
				pageSize: 0,
				statusList: statusList,
				wxOpenid: uni.getStorageSync('openid_key')
			}
			orderInfo.queryByPage(param).then(result => {
				const total = result.data.data.total || ''
				this.orderNum[key] = total
			}).catch(error => {
				console.log(error);
			})
		},
		navToMyOrderList(type) {
			uni.navigateTo({
				url: '/patientAppPages/pages/myOrderList/myOrderList?type=' + type
			})
		},
		navToInfo() {
			// uni.navigateTo({
			// 	url: '/patientAppPages/pages/personalInformation/personalInformation'
			// })
			uni.navigateTo({
				url: "/pages/feixiang/login/getMess"
			})
		},
		queryCountByComm() {
			const param = {
				wxOpenid: uni.getStorageSync('openid_key')
			}
			orderInfo.queryCountByComm(param).then(result => {
				this.countInfo = result.data.data
			}).catch(error => {
				console.log(error);
			})
		}
	}
}
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss" scoped>
page {
	background: #F8F8F8;
}

.top-view {
	width: 100%;
	height: 400rpx;
	// background: url('../../static/mine_nav_bg.png');
	background-repeat: no-repeat;
	background-size: 100% 100%;
	display: flex;
	flex-direction: column;

	.user-row {
		width: 100%;
		display: flex;
		padding: 0 50rpx;
		box-sizing: border-box;
		margin-bottom: 15rpx;

		.avatar {
			width: 110rpx;
			height: 110rpx;
			border-radius: 50%;
		}

		.name-view {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			margin-left: 22rpx;

			.name {
				color: #232323;
				font-size: 38rpx;
				font-weight: bold;
			}

			.phone {
				color: rgba(35, 35, 35, 0.5);
				font-size: 14.35px;
			}
		}

		.right-btn {
			display: flex;
			align-items: center;

			.item-go {
				width: 30rpx;
				height: 30rpx;
			}
		}

	}
}

.mine-order-card {
	border-radius: 20rpx !important;
	margin-top: -100rpx;
	margin-left: 30rpx;
	margin-right: 30rpx;
	padding: 30rpx;
	box-sizing: border-box;
	background: white;

	.title-view {
		width: 100%;
		display: flex;

		.title {
			flex: 1;
			color: #232323;
			font-size: 28rpx;
			font-weight: bold;
		}

		.right-view {
			display: flex;
			align-items: center;
			color: rgba(35, 35, 35, 0.5);
			font-size: 24rpx;

			image {
				width: 30rpx;
				height: 30rpx;
				margin-left: 4rpx;
			}
		}
	}

	.grid-view {
		margin-top: 20rpx;

		.grid-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			position: relative;

			.icon {
				width: 48rpx;
				height: 68rpx;
				padding: 15rpx 0;
			}

			.text {
				color: #232323;
				font-size: 24rpx;
				font-weight: 400;
			}

			.grid-dot {
				position: absolute;
				right: 30rpx;
				top: 0;
			}
		}

	}

}


.menu-list {
	margin-top: 20rpx;
	margin-left: 30rpx;
	margin-right: 30rpx;
	background: white;
	border-radius: 20rpx;
	overflow: hidden;
	padding: 20rpx;
}

.exit-btn {
	margin-top: 60rpx;
	margin-left: 30rpx;
	margin-right: 30rpx;
	background: white;
	border-radius: 12rpx;
	padding: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	color: rgba(35, 35, 35, 0.7);
	font-size: 28rpx;
}
</style>
